package br.com.tas;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import br.com.tas.dao.CoordinatesDao;
import br.com.tas.dao.interfaces.ICoordinatesDao;
import br.com.tas.exception.DataException;
import br.com.tas.model.CoordinatesBean;

public class MainActivity extends Activity {

	private ICoordinatesDao coordinatesDao;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		coordinatesDao = new CoordinatesDao(this);
		validateCoordinatesBeansSize();
	}
	
	private boolean validateCoordinatesBeansSize() {
		List<CoordinatesBean> coordinatesBeans = null;

		try {
			coordinatesBeans = coordinatesDao.findAll(new CoordinatesBean());
			
			if (coordinatesBeans == null) {
				startCoordinatesActivity();
				finish();
			} else if (coordinatesBeans.size() > 0) {
				startListCoordinatesActivity();
				finish();
			} 
		} catch (DataException e) {
			e.printStackTrace();
		}
		
		return true;
	}
	
	private void startCoordinatesActivity(){
    	Intent intent = new Intent(this, CoordinatesActivity.class);
    	startActivity(intent);
    }
	
	private void startListCoordinatesActivity(){
    	Intent intent = new Intent(this, ListCoordinatesActivity.class);
    	startActivity(intent);
    }
}
